#include <types.h>
#include <HTTPMessageResponse.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

HTTPMessageResponse::HTTPMessageResponse()
{
    memset(content, 0, sizeof(content));
}


HTTPMessageResponse::~HTTPMessageResponse()
{
    
}


void HTTPMessageResponse::setContent(char *buf)
{
    strncpy(content, buf, MIN(sizeof(content), strlen(buf)));
}


void HTTPMessageResponse::getHeaders(char *buf, int bufsize)
{
    char *mig;
    
    mig=strstr(content, "\r\n\r\n");
    
    if (mig==NULL)
    {
	mig=strstr(content, "\n\n");
	if (mig==NULL)
	    return;
    }
    *mig=0;    
    strncpy(buf, content, bufsize);
    *mig='\r';	    
}


void HTTPMessageResponse::getData(char *dest, int bufsize)
{
    char *mig;
    
    mig=strstr(content, "\r\n\r\n");
    if (mig==NULL)
    {
	mig=strstr(content, "\n\n");
	if (mig==NULL)
	    return;
    }

    strncpy(dest, mig+4, bufsize);
}
